home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / ShareMailGiftware / AmigaTalk / general / Semaphore.st < prev    next >
Text File  |  2002-10-27  |  800b  |  31 lines

  1. "-----------------------------------------------------------"
  2. " Semaphore Class is NOT the same as Amiga Exec Semaphores. "
  3. "-----------------------------------------------------------"
  4.  
  5. Class Semaphore :List ! excessSignals !
  6. [  
  7.    new
  8.       excessSignals <- 0
  9. |  
  10.    new: aNumber
  11.       excessSignals <- aNumber
  12. |  
  13.    signal
  14.       <primitive 148>.   "start atomic action"
  15.  
  16.       (self isEmpty)
  17.          ifTrue:  [excessSignals <- excessSignals + 1]
  18.          ifFalse: [self removeFirst unblock].
  19.  
  20.       <primitive 149>    "end atomic action"
  21. |  
  22.    wait
  23.       <primitive 148>.   "start atomic actions"
  24.  
  25.       (excessSignals = 0)
  26.          ifTrue: [self addLast: selfProcess.  selfProcess block]
  27.         ifFalse: [excessSignals <- excessSignals - 1].
  28.  
  29.       <primitive 149>    "end atomic actions"
  30. ]
  31.